
#ifndef _XBUFFER_H_
#define _XBUFFER_H_

#include "xtypes.h"

#define DEFAULT_BUFFER_SIZE (0x1000)

class CxStaticBuffer
{
public:
	memptr_t data() const;
	int_t size() const;

	int_t capacity() const;
	xResult resize_capacity(int_t _NewSize);

public:
	CxStaticBuffer();
	CxStaticBuffer(int_t _Size);
	CxStaticBuffer(const CxStaticBuffer& _Ref);
	CxStaticBuffer& operator=(const CxStaticBuffer& _R);
	CxStaticBuffer(const wildptr_t _DataPtr, int_t _Size);
	~CxStaticBuffer();

protected:
	void _Init();
	void _Alloc(int_t _Size);
	void _Tidy();
	void _Copy(const CxStaticBuffer& _Ref);


protected:
	memptr_t m_PhyPtr;	
	int_t m_PhySize;

};

class CxDynamicBuffer
{
public:
	memptr_t data() const;
	int_t size() const;
	xResult resize( int_t _Size );
	int_t capacity() const;
	xResult resize_capacity(int_t _NewSize);

	bool_t empty() const;
	xResult clear();

	xResult insert_front( const wildptr_t _DataPtr, int_t _Size );
	xResult drop_front( int_t _Size );
	xResult copy_front( wildptr_t _DataPtr, int_t _Size ) const;	
	xResult cut_front( wildptr_t _DataPtr, int_t _Size );

	xResult insert_back( const wildptr_t _DataPtr, int_t _Size );
	xResult drop_back( int_t _Size );
	xResult copy_back( wildptr_t _DataPtr, int_t _Size ) const;	
	xResult cut_back( wildptr_t _DataPtr, int_t _Size );

	xResult insert( int_t _BeginPos, const wildptr_t _DataPtr, int_t _Size );
	xResult drop( int_t _BeginPos, int_t _Size );
	xResult copy( int_t _BeginPos, wildptr_t _DataPtr, int_t _Size ) const;	
	xResult cut( int_t _BeginPos, wildptr_t _DataPtr, int_t _Size );

public:
	CxDynamicBuffer();
	CxDynamicBuffer(int_t _Size);
	CxDynamicBuffer(const CxDynamicBuffer& _Ref);
	CxDynamicBuffer& operator=(const CxDynamicBuffer& _R);
	CxDynamicBuffer(const wildptr_t _DataPtr, int_t _Size);
	~CxDynamicBuffer();


protected:
	void _Init();
	void _Alloc(int_t _Size);
	void _Tidy();
	void _Copy(const CxDynamicBuffer& _Ref);


protected:
	memptr_t m_PhyPtr;	
	int_t m_PhySize;
	int_t m_DataSize;

};


class CxRingBuffer
{
public:
	memptr_t data();
	int_t size() const;
	xResult resize( int_t _Size );
	int_t capacity() const;
	xResult resize_capacity(int_t _NewSize);

	bool_t empty() const;
	xResult clear();

	xResult insert_front( const wildptr_t _DataPtr, int_t _Size );
	xResult drop_front( int_t _Size );
	xResult copy_front( wildptr_t _DataPtr, int_t _Size ) const;	
	xResult cut_front( wildptr_t _DataPtr, int_t _Size );

	xResult insert_back( const wildptr_t _DataPtr, int_t _Size );
	xResult drop_back( int_t _Size );
	xResult copy_back( wildptr_t _DataPtr, int_t _Size ) const;	
	xResult cut_back( wildptr_t _DataPtr, int_t _Size );

	xResult insert( int_t _BeginPos, const wildptr_t _DataPtr, int_t _Size );
	xResult drop( int_t _BeginPos, int_t _Size );
	xResult copy( int_t _BeginPos, wildptr_t _DataPtr, int_t _Size ) const;	
	xResult cut( int_t _BeginPos, wildptr_t _DataPtr, int_t _Size );

	int_t length();
	memptr_t fragment_ptr();
	int_t fragment_len();


public:
	CxRingBuffer();
	CxRingBuffer(int_t _Size);
	CxRingBuffer(const CxRingBuffer& _Ref);
	CxRingBuffer& operator=(const CxRingBuffer& _R);
	CxRingBuffer(const wildptr_t _DataPtr, int_t _Size);
	~CxRingBuffer();


protected:
	void _Init();
	void _Alloc(int_t _Size);
	void _Tidy();
	void _Copy(const CxRingBuffer& _Ref);

	void _Serialize();

protected:
	memptr_t m_PhyPtr;	
	int_t m_PhySize;
	int_t m_nHead;
	int_t m_DataSize;
};



#endif //_XBUFFER_H_



